package com.silence.gmall.product.controller;

import com.silence.gmall.annotations.Log;
import com.silence.gmall.base.Result;
import com.silence.gmall.product.domain.repository.BaseSaleAttrRepository;
import com.silence.gmall.product.domain.repository.SpuSaleAttrRepository;
import com.silence.gmall.product.dto.BaseSaleAttrDto;
import com.silence.gmall.product.dto.SpuSaleAttrDto;
import com.silence.gmall.product.service.BaseSaleAttrService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author silence
 * @Description 销售属性控制器
 * @Date 2025-08-17 16:28:16
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/product")
public class SaleAttrController {

    /**
     * BaseSaleAttrService 的注入
     */
    private final BaseSaleAttrService baseSaleAttrService;

    /**
     * BaseSaleAttrRepository 的注入
     */
    private final BaseSaleAttrRepository baseSaleAttrRepository;

    /**
     * SpuSaleAttrRepository 的注入
     */
    private final SpuSaleAttrRepository spuSaleAttrRepository;

    /**
     * 获取销售属性
     *
     * @return 销售属性集合
     */
    @GetMapping("/baseSaleAttrList")
    @Log(interfaceName = "获取销售属性")
    public Result<List<BaseSaleAttrDto>> baseSaleAttrList() {
        return Result.build(baseSaleAttrRepository.baseSaleAttrList());
    }

    /**
     * 根据spuId获取销售属性
     *
     * @param spuId spuId
     * @return 销售属性
     */
    @GetMapping("/spuSaleAttrList/{spuId}")
    @Log(interfaceName = "根据spuId获取销售属性")
    public Result<List<SpuSaleAttrDto>> spuSaleAttrList(@PathVariable("spuId") Long spuId) {
        return Result.build(spuSaleAttrRepository.spuSaleAttrList(spuId));
    }
}